<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/MarketRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/ShopRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/UserRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form>
    <center>
        <input type="hidden" id="userType" name="userType" value="41">
        <table style="width: 50%;" cellpadding="5" cellspacing="5">
            <tr>
                <td>
                    <select id="marketId" name="marketId" onchange="getShopList()">
                    </select>
                </td>
                <td>
                    <select id="shopId" name="shopId" onchange="getStaffPage()">
                    </select>
                </td>
                <td>
                    <button type="button" onclick="submitStaff('')">新增车商员工</button>
                </td>
            </tr>
        </table>
    </center>
</form>
<br>
<SCRIPT LANGUAGE="JavaScript" >
    var staffThead = new Array(
        new XThead("姓名"),
        new XThead("手机号"),
        new XThead("用户类型"),
        new XThead("所属公司"),
        new XThead("状态"),
        new XThead("操作")
    );

    var staffXTable = new XTable("staff", staffThead);

    var state_hash = {
        "0":"无效",
        "1":"正常",
    }
    staffXTable.XTbodyArray = function (model) {
        var array = new Array(
            new XTbody("staff", model.userName, "string", null, null, "center"),
            new XTbody("staff", model.userMobile, "string", null, null, "center"),
            new XTbody("staff", model.userRemark, "string", null, null, "center"),
            new XTbody("staff", model.market.marketName, "string", null, null, "center"),
            new XTbody("staff", state_hash[model.userState], "string", null, null, "center"),
            new XTbody("staff", "<a href='#' onclick=submitStaff('"+ model.userId +"')>编辑</a>", "string", null, null, "center")
        );
        return array;
    }

    staffXTable.getXList = function (page){
        var staff = new User();
        staff.userType = dwr.util.getValue("userType");
        staff.shopId = dwr.util.getValue("shopId");
        staff.pageIndex = page;
        staff.pageSize = staffXTable.pageSize;
        UserRpcService.selectUserList(staff, function(list){staffXTable.addTable(list);});
    }
    function getStaffPage() {
        var staff = new User();
        staff.userType = dwr.util.getValue("userType");
        staff.shopId = dwr.util.getValue("shopId");
        staff.marketId = dwr.util.getValue("marketId");
        UserRpcService.selectUserNum(staff, function(num){staffXTable.setTotalPage(num);}) ;
    }
</SCRIPT>
</body>
</html>
<script>

    //    显示市场列表
    var market = new Market();
    market.marketId = "${marketId}";
    MarketRpcService.selectMarketList(market, callbackSelectMarketList);

    function callbackSelectMarketList(list) {
        dwr.util.addOptions("marketId", list, "marketId", "marketName");
        dwr.util.setValue("marketId", "${marketId}");
        if ("${shopId}" )
        getShopList();
        getStaffPage();
    }

    function getShopList(){
        var shop = new Shop();
        shop.marketId = dwr.util.getValue("marketId");
        shop.shopState = "1";
        ShopRpcService.selectShopList(shop, callbackSelectShopList);
    }

    function callbackSelectShopList(list) {
        dwr.util.removeAllOptions("shopId");
        dwr.util.addOptions("shopId", {"" : "请选择"});
        dwr.util.addOptions("shopId", list, "shopId", "shopName");
        dwr.util.setValue("shopId", "${shopId}");
        if ("${shopId}".length > 0){
           $("shopId").disabled = true;
        }
        getStaffPage();
    }

    function submitStaff(staffId){
        location = "${ctx}/user/staff_manage.jsp?staffId=" + staffId;
    }
</script>
